package com.visec.hdy.sync.ftp.config;

import java.io.Closeable;
import java.io.IOException;

import com.visec.hdy.transmission.ftp.FtpFactory;
import com.visec.hdy.transmission.ftp.code.FtpClientInter;
import com.visec.hdy.transmission.ftp.config.FtpModel;
import com.visec.hdy.transmission.socket.SocketFactory;
import com.visec.hdy.transmission.socket.code.SocketClient;
import com.visec.hdy.transmission.socket.config.SocketModel;

public class FtpSendClient implements Closeable {
	private FtpClientInter ftpClientInter;
	private SocketClient socketClient;

	public FtpSendClient(FtpModel ftpModel, SocketModel socketModel) {
		this.ftpClientInter = FtpFactory.getInstance().createClient(ftpModel);
		this.socketClient = SocketFactory.getInstance().createClient(socketModel);
	}

	public FtpSendClient(FtpClientInter ftpClientInter, SocketClient socketClient) {
		super();
		this.ftpClientInter = ftpClientInter;
		this.socketClient = socketClient;
	}

	public FtpSendClient copy() {
		return new FtpSendClient(ftpClientInter.copy(), socketClient.copy());
	}

	public FtpClientInter getFtpClientInter() {
		return ftpClientInter;
	}

	public void setFtpClientInter(FtpClientInter ftpClientInter) {
		this.ftpClientInter = ftpClientInter;
	}

	public SocketClient getSocketClient() {
		return socketClient;
	}

	public void setSocketClient(SocketClient socketClient) {
		this.socketClient = socketClient;
	}

	@Override
	public void close() throws IOException {
		// TODO Auto-generated method stub
		if (this.socketClient != null){
			this.socketClient.close();
		}
		if (this.ftpClientInter != null)
			this.ftpClientInter.logout();
	}

}
